/**
 * 
 */
package partitioning;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author puneet
 * 
 */
public class TCPListener {
	private int port;

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public TCPListener(int port) {
		this.port = port;
	}
	
	public String blockWaitForMessage()throws IOException {
		System.out.println("About to start listening");
		ServerSocket ss = new ServerSocket(port);
		Socket socket = ss.accept();
		BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		String msg = br.readLine();
		System.out.println("Received message:" + msg);
		socket.close();
		ss.close();
		return msg;
	}
}
